package thread.test_3.demo_2;

public class Cooker extends Thread{
    private Desk desk;
    public Cooker (Desk desk) {
        this.desk = desk;
    }
    @Override
    public void run() {
        while (true) {
            synchronized(desk) {
                if (desk.getFood() == 0) {
                    break;
                } else {
                    if (desk.isFlag()) {
                        try {
                            desk.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    } else {
                        System.out.println("老八做了个蜜汁汉堡");
                        desk.setFlag(true);
                        desk.notify();
                    }
                }
            }
        }
    }
}
